<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class OrderGoods extends Model
{

    /**
     * 表名称
     * @var $table;
     */
    protected $table = 'order_goods';

    /**
     * 主键
     * @var $primaryKey
     */
    protected $primaryKey = 'id';

    /**
     * 时间戳   laravel ORM 自动维护数据库时间戳,用户数据结构的回滚操作,默认开启,我们禁止
     * @var bool $timestamps
     */
    public $timestamps = false;

    protected $appends = array('mobile_goods_thumb');

    /**
     * 自动填充字段
     * @var $fillable
     */
    protected $fillable = ['sub_order_id', 'goods_id', 'goods_sn', 'goods_name', 'goods_pet_name', 'goods_desc', 'buy_number', 'goods_weight', 'shop_price', 'tariff_percent', 'goods_thumb', 'shop_id', 'cat_id', 'type'];


    public function getMobileGoodsThumbAttribute()
    {
        $goods_thumb = $this->getAttribute('goods_thumb');

        $return = '';


        if ($goods_thumb) {
            if(Picture::find($goods_thumb)){
                return Picture::find($goods_thumb)->url;
            }else{
                return null;
            }

        }

        return $return;

    }

}
